# 安装pymysql
# pip install pymysql

import pymysql

# 1、创建数据库练级
connect = pymysql.connect(host="cdh01",
                          port=3306,
                          user="root",
                          passwd="123456",
                          database="bigdata25")
# 2、创建游标
cursor = connect.cursor()

# 3、编写sql查询数据
cursor.execute("select * from users")

# 4、获取查询到的所有的数据
users = cursor.fetchall()

# 5、循环打印结果
for user in users:
    print(user)

# 6、插入数据
cursor.execute("insert into users values('003','王五',25)")

# 提交事务
connect.commit()

# 关闭连接
connect.close()
